package ru.pachkun.home.logic;

import org.openqa.selenium.By;

import ru.pachkun.home.logicinterface.NavigationHelperInterface;

public class NavigationHelper extends DriverBasedHelper implements
		NavigationHelperInterface {

	private String baseUrl;

	public NavigationHelper(ApplicationManager manager) {
		super(manager.getWebDriver());
		this.baseUrl = manager.getBaseUrl();
	}

	@Override
	public void openMainPage() {
		driver.get(baseUrl);
	}

	@Override
	public void openRelativeUrl(String url) {
		driver.get(baseUrl + url);
		pages.internalPage.ensurePageLoaded();
	}

	@Override
	public void gotoUserProfilePage() {
		pages.internalPage.ensurePageLoaded().clickUserProfilePage();
		driver.findElement(By.cssSelector("nav a[href $= '?go=profile']"))
				.click();
		openRelativeUrl("?go=profile");
	}

	@Override
	public void gotoUserManagementPage() {
		pages.internalPage.ensurePageLoaded().clickUserManagementLink();
		driver.findElement(By.cssSelector("nav a[href $= '?go=users']"))
				.click();
		openRelativeUrl("?go=users");
	}

}
